**Authors: Geoffrey Sheagley & Logan Dancey 

**Date: 4/25/17

**Intent: Replicate party unity experiment 

**Required File: ExperimentData_Clean 

*********************

keep unity_score Q71 Party Q84 Q85 Q87 

**Data Formatting 

tab unity_score
gen us2 = real(unity_score) 
tab us2

gen approve = Q71
tab approve

gen approve2 = 4-abs(approve)
tab approve2

gen approve_binary = 1 if approve==1 | approve==2
replace approve_binary = 0 if approve==3 | approve==4

tab approve_binary

tab approve_binary approve2

*Legislator Party 

gen rep_party = 1 if Party=="Democratic" 
replace rep_party = 2 if Party=="Republican" 

label define rep_party 1 "Democrat" 2 "Republican" 
label values rep_party rep_party 
tab rep_party

*Respondent Party 

tab1 Q84 Q85 Q87

gen pid3 = 1 if Q84==1 
replace pid3 = 1 if Q87==1
replace pid3 = 2 if Q87==3
replace pid3 = 3 if Q84==2
replace pid3 = 3 if Q87==2

label define pid3 1 "Republican" 2 "Independent" 3 "Democrat" 
label values pid3 pid3
tab pid3

gen pidstrength = 1 if pid3==2
replace pidstrength = 2 if Q87 == 1 | Q87==2 
replace pidstrength = 3 if Q85==2 
replace pidstrength = 4 if Q85== 1
tab pidstrength

gen pidstrength2 = pidstrength if pidstrength>1
replace pidstrength2 = pidstrength2-1
tab pidstrength2

*Party Agreement 

gen ptyagree=. 
replace ptyagree = 0 if pid3 == 1 & rep_party==1
replace ptyagree = 0 if pid3 == 3 & rep_party==2
replace ptyagree = 1 if pid3 == 1 & rep_party==2
replace ptyagree = 1 if pid3 == 3 & rep_party==1
replace ptyagree = 2 if pid3==2
tab ptyagree
label define ptyagree 0 "Opp. Partisan" 1 "Co-Partisan" 2 "Indepdent" 
label values ptyagree ptyagree
tab ptyagree


***Analyses 

*Model 1  -- Approval as function of Party ID and Unity
logit approve_binary i.ptyagree pidstrength c.us2
margins, predict() at(us2=(50(50)100))

*Model 2 & 3 -- Testing for Non-Linear Efffects on Approval
logit approve_binary i.ptyagree##c.us2 pidstrength
est store mod1 

logit approve_binary i.ptyagree##c.us2##c.us2 pidstrength
est store mod2

lrtest mod1 mod2

margins, predict() at(us2=(50(5)100) ptyagree=(0(1)1))

marginsplot, recastci(rarea) recast(line) ///
	plot2opts(col(gray) fcol(gs10)) ///
	plot1opts(col(black)) ///
	ci1opts(col(gs10)) ///
	ci2opts(col(gs3)) ///
	title("Effect of Treatment by Party Agreement vs. Disagreement on MC Approval", size(medium)) ///
	xlabel(50(10)100, labsize(medium))  xtitle("Manipulated Party Unity Score") ///
	ylabel(0.2(0.2)0.8, labsize(medium)) ytitle("Predicted Probability") ///
	legend(pos(12) order(1 "Opposition Parisan" 2 "Co-Partisan") rows(1) holes(1 2))
	
*Model 3 -- Differential Effects by Party Strength
logit approve_binary i.ptyagree##i.pidstrength##c.us2##c.us2

margins, predict() at(us2=(50(5)100) ptyagree=1 pidstrength=(3(1)4))
marginsplot, recastci(rarea) recast(line) ///
	plot2opts(col(gray) fcol(gs10)) ///
	plot1opts(col(black)) ///
	ci1opts(col(gs10)) ///
	ci2opts(col(gs3)) ///
	title("Co-Partisan Respondent", size(medium)) ///
	xlabel(50(10)100, labsize(medium))  xtitle("Manipulated Party Unity Score") ///
	ylabel(0.2(0.2)0.8, labsize(medium)) ytitle("Predicted Probability") ///
	legend(pos(12) order(1 "Weak Partisan" 2 "Strong Partisan") rows(1) holes(1 2))
	

**Bar Graph from SI 

graph bar (mean) approve_binary if ptyagree !=2, over(us2) over(ptyagree) ///
ylabel(0 .2 "20" .4 "40" .6 "60" .8 "80") ytitle(Percent Approving of Legislator) ///
title(Approval of Legislator by Party Unity Treatment) subtitle (By Partisan Status) 





